//
//  BLDanmuServer.swift
//  BLLiveTelecast
//
//  Created by BigL055 on 16/6/21.
//  Copyright © 2016年 bigL.liveTelecast.com. All rights reserved.
//

import UIKit

class BLDanmuServerTool: NSObject {
    
    // 单例对象
    static let shareInstance: BLDanmuServerTool = BLDanmuServerTool()

    // 认证连接
    var authSocket : BLAuthSocket?
    // 弹幕服务器连接
    var danmuSocket : BLDanmuSocket?

    
    /// 链接弹幕服务
     func startServer(roomID : String) {
        
        // 调试模式
        guard Debug_isAllowDanmuPlay else{
            return
        }
        
        //链接服务器
        authSocket = BLAuthSocket.sharedInstance
        authSocket?.room = roomID
        authSocket?.connectSocketHost()
        
        danmuSocket = BLDanmuSocket.sharedInstance
        danmuSocket?.room = authSocket?.room ?? ""
        
        weak var weakSelf = self
        authSocket?.InfoBlock = {(vistorID : String, groupID : String) in ()
            weakSelf!.danmuSocket?.vistorID = vistorID
            weakSelf!.danmuSocket?.groupID = groupID
            weakSelf!.danmuSocket?.connectSocketHost()
        }
    }

    /// 断开弹幕服务
    func cutServer() {
        
        // 调试模式
        guard Debug_isAllowDanmuPlay else{
            return
        }
        
        authSocket?.cutOffSocket()
        danmuSocket?.cutOffSocket()
    }
}
